package main

import (
	"fmt"
	"strings"
	"time"
)

type Params map[string]interface{}
type Show struct {
	Params
}

type Student struct {
	name string
}

func (s *Student) String() string {
	return fmt.Sprintf("%v\n", s)
}

func getType(obj interface{}) {
	//switch ss := obj.(type) {
	//case Student:
	//	fmt.Println(ss.Name)
	//case *Student:
	//	fmt.Println(ss.Name)
	//}
}
func main() {
	ch := make(chan int, 20)
	go func() {
		for i := 0; i < 10; i++ {
			ch <- i
		}
	}()
	go func() {
		for {
			v, ok := <-ch
			if !ok {
				fmt.Println("closed")
				return
			}
			fmt.Println("i = ", v)
		}
	}()
	defer close(ch)
	fmt.Println("okkkk")
	time.Sleep(time.Second * 5)
	//var stu Student
	//data := []byte(`{"name":"mch"}`)
	//err := json.Unmarshal(data, &stu)
	//if err != nil {
	//	fmt.Println(err)
	//} else {
	//	fmt.Println(stu)
	//}
	//stu := Student{name: "mch"}
	//bt, err := json.Marshal(stu)
	//if err != nil {
	//	fmt.Println(err)
	//} else {
	//	fmt.Println(bt)
	//	fmt.Printf("%s\n", bt)
	//}
	//
	//var student Student
	//err = json.Unmarshal(bt, &student)
	//if err != nil {
	//	fmt.Printf("error : %s\n", err)
	//} else {
	//	fmt.Printf("%#v \n", student)
	//}
	//show := new(Show)
	//show.Params = make(Params)
	//show.Params["name"] = "mch"
	//fmt.Println(show)
	//str1 := "爱我你中国 123"
	//str1 := "abc dAz"
	//reverseStr(&strsss)
	//fmt.Println(strsss)
	//fmt.Println(reverseRun(strsss))
	//str2 := "我爱你中国123"
	//if checkStr(str1, str2) {
	//	fmt.Println("yiyang")
	//} else {
	//	fmt.Println("do not same")
	//}
	//s1 := sortStr([]rune(str1))
	//s2 := sortStr([]rune(str2))
	//if string(s1) == string(s2) {
	//	fmt.Println("same")
	//
	//} else {
	//	fmt.Println("not same")
	//}
	//fmt.Println(replaceStr(str1))
}

func replaceStr(s string) (string, bool) {
	ss := []rune(s)
	newS := make([]rune, 0)
	repl := []rune("%20")
	for _, v := range ss {
		if v != ' ' && (v > 'z' || v < 'a') && (v > 'Z' || v < 'A') {
			return "", false
		}
		if v == ' ' {
			newS = append(newS, repl...)
		} else {
			newS = append(newS, v)
		}

	}
	return string(newS), true
}
func sortStr(s []rune) []rune {
	strLen := len(s)
	flag := true
	for k, _ := range s {
		if strLen-1 > k && s[k] > s[k+1] {
			s[k], s[k+1] = s[k+1], s[k]
			flag = false
		}
	}
	if flag {
		return s
	} else {
		return sortStr(s)
	}
}

func checkStr(s1, s2 string) bool {
	strs1 := []rune(s1)
	strs2 := []rune(s2)
	if len(strs1) != len(strs2) {
		return false
	}
	for _, v := range strs1 {
		if strings.Count(s1, string(v)) != strings.Count(s2, string(v)) {
			return false
		}
	}
	return true

}
func reverseRun(str string) (string, bool) {
	strs := []rune(str)
	lens := len(strs)
	for i := 0; i < lens/2; i++ {
		strs[i], strs[lens-1-i] = strs[lens-1-i], strs[i]
	}
	return string(strs), true
}
func reverseStr(str *string) bool {
	strs := []int32(*str)
	strLen := len(strs)
	for key, _ := range strs {
		if key >= (strLen / 2) {
			break
		}
		strs[key], strs[strLen-1-key] = strs[strLen-1-key], strs[key]
	}
	*str = string(strs)
	return true
}
func st() bool {
	str := "abcdef123"
	if len(str) > 3000 {
		return false
	}
	for k, v := range str {
		if v > 256 {
			return false
		}
		for kk, vv := range str {
			if kk != k && v == vv {

				return false
			}
		}
	}
	return true
}
